import { IBusiness } from "../../app_base/module/business/IBusiness";

export class AudioBusiness implements IBusiness {

    start(): IBusiness {
        if(cc.game['_prepare']) {
            this._registerEvent();
        }else {
            cc.game.on(cc.game.EVENT_GAME_INITED, this._registerEvent, this);
        }
        return this;
    }

    private _registerEvent():void {
        cc.game.on(cc.game.EVENT_HIDE, this._onHide, this);
        cc.game.on(cc.game.EVENT_SHOW, this._onShow, this);
    }

    private _unregisterEvent():void {
        cc.game.off(cc.game.EVENT_HIDE, this._onHide, this);
        cc.game.off(cc.game.EVENT_SHOW, this._onShow, this);
    }

    private _onHide():void {
        cc.audioEngine.pauseAll();
    }

    private _onShow():void {
        cc.audioEngine.resumeAll();
    }

    stop(): void {
        this._unregisterEvent();
    }

    pause(): void {
        
    }

    release(): void {
        this._unregisterEvent();
    }
}
